<?php
namespace Lisheng\HiAdmin\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;

class HiAdminController{

	public function __construct(){

		
	}

	public function getLogin(){

		return view('admin.auth.login');
	}

	public function postLogin(Request $request){

		$credentials = $request->only(['email','password']);

		$validator = Validator::make($credentials,[
				'email'=>'required',	
				'password'=>'required'
			]);

		if($validator->fails())
		{
			return redirect('admin/auth/login')
                        ->withErrors($validator);		
		}

		if(Auth::guard()->attempt($credentials))
		{
			return redirect()->intended('/admin/home');
		}

		 return Redirect::back()->withErrors(['email' => 'invalid user']);
	}

}